﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using MySql.Data.MySqlClient;

namespace Progrom
{
    public partial class inforMsg : Form
    {
        public inforMsg()
        {
            InitializeComponent();
        }

        private MySqlDataAdapter da = new MySqlDataAdapter();
        private DataSet ds = new DataSet("MyScool");


        private void ShowCourses()
        {
            string connString = @"server=localhost;User Id=root;password=123456;database=myschool;Character Set=utf8";
            string sql = "select CourseId as 课程ID,CourseName as 课程名称,CourseClass as 课程类别,Required 是否必修,Credit as 学分,PrelectionCredit as 理论学时,ExperimentCredit as 实验学时 from CourseMsg";
            MySqlConnection conn = new MySqlConnection(connString);
            conn.Open();
            MySqlCommand comm = new MySqlCommand(sql, conn);
            da.SelectCommand = comm;
            MySqlCommandBuilder builder = new MySqlCommandBuilder(da);
            da.Fill(ds, "CourseMsg");
            dgvCourse.DataSource = ds.Tables["CourseMsg"];
            conn.Close();
        }
        private void CourseFrm_Load(object sender, EventArgs e)
        {
            ShowCourses();
        }

        private void btnSave_Click_1(object sender, EventArgs e)
        {
            da.Update(ds, "CourseMsg");
            MessageBox.Show("数据更新已经成功保存！", "注意", MessageBoxButtons.OKCancel, MessageBoxIcon.Warning);
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            if (MessageBox.Show("您是否真的要取消目前添加、修改或删除操作？", "注意", MessageBoxButtons.OKCancel, MessageBoxIcon.Question) == DialogResult.OK)
            {
                ds.Clear();
                ShowCourses();
                dgvCourse.Refresh();
            }

        }

        private void inforMsg_Load(object sender, EventArgs e)
        {
            ShowCourses();
        }
    }
}
